package cn.tedu.demo.controller;

import cn.tedu.demo.common.Result;
import cn.tedu.demo.entity.News;
import cn.tedu.demo.service.NewsService;
import cn.tedu.demo.vo.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/news")
public class NewsController {
    @Autowired
    private NewsService newsService;

    @PostMapping
    public Result<?> save(@RequestBody News news) {
        newsService.save(news);
        return Result.success();
    }

    @PutMapping
    public Result<?> update(@RequestBody News news) {
        newsService.update(news);
        return Result.success();
    }


    @GetMapping("/list")
    public Result<?> getByPage(PageInfo pageInfo) {
        pageInfo = newsService.getByPage(pageInfo);
        return Result.success(pageInfo);
    }

    @DeleteMapping("/delete/{id}")
    public Result<?> delete(@PathVariable Long id) {
        newsService.delete(id);
        return Result.success();
    }

}
